﻿@*page:AppVersionEdit.razor*@
@*gardener-time:2024-07-16 17:48:43*@
@inherits EditOperationDialogBase<AppVersionDto, Int64,AppManagerResource>

<Form @ref="_editForm"
      Loading="_dialogLoading.Value"
      Model="_editModel"
      LabelCol="new ColLayoutParam { Span = 6 }"
      WrapperCol="new ColLayoutParam { Span = 18 }"
      OnFinish="OnFormFinish"
      ValidateMode="FormValidateMode.Complex"
      Context="model">

      @if (!base.OperationIs(OperationDialogInputType.Add))
    {
        <FormItem>
            <InputNumber @bind-Value="model.Id" Disabled="true" Bordered="false" />
    </FormItem>
    }
    <FormItem>
        <Select TItem="AppDto"
                TItemValue="Guid"
                @bind-Value="model.AppId"
                DataSource="_apps"
                Disabled="base.operationIsOnlyReadData"
                ItemValue="x=>x.Id"
                ItemLabel="x=>x.AppName"
                DefaultActiveFirstOption
                Bordered="base.operationCanChangeData">
        </Select>
    </FormItem>
    <FormItem>
        <Input @bind-Value="model.PackageName" Disabled="base.operationIsOnlyReadData" Bordered="base.operationCanChangeData" />
    </FormItem>
    <FormItem Rules="[_uniqueValueValidatorRuleNumber]">
        <InputNumber @bind-Value="model.VersionNumber" Disabled="base.operationIsOnlyReadData" Bordered="base.operationCanChangeData" />
    </FormItem>
    <FormItem Rules="[_uniqueValueValidatorRule]">
        <Input @bind-Value="model.VersionName" Disabled="base.operationIsOnlyReadData" Bordered="base.operationCanChangeData" />
    </FormItem>
    <FormItem>
        <TextArea AutoSize="true" MinRows="2" MaxRows="6" @bind-Value="@model.VersionDescription" Disabled="base.operationIsOnlyReadData" Bordered="base.operationCanChangeData"></TextArea>
    </FormItem>
    <FormItem>
        <TextArea AutoSize="true" MinRows="2" MaxRows="6" @bind-Value="model.AppUrl" Disabled="base.operationIsOnlyReadData" Bordered="base.operationCanChangeData"></TextArea>
        @if (!model.AppId.Equals(Guid.Empty) && UploadParams != null && base.operationCanChangeData)
        {
            <Gardener.Core.Client.Components.MultiFileUpload UploadParams="UploadParams" OnSingleCompleted="OnSingleCompleted" />
        }
    </FormItem>
    <FormItem>
        <Input @bind-Value="model.FileName" Disabled="base.operationIsOnlyReadData" Bordered="base.operationCanChangeData" />
    </FormItem>
    <FormItem>
        <Switch @bind-Value="@model.ForcedUpdating" Disabled="base.operationIsOnlyReadData"></Switch>
    </FormItem>
    <FormItem>
        <ResourceAuthorize ResourceKey="app_manager_app_version_lock">
            <Authorized>
                <Switch @bind-Value="@model.IsLocked" Disabled="base.operationIsOnlyReadData"></Switch>
            </Authorized>
            <NotAuthorized>
                <Switch @bind-Value="@model.IsLocked" Disabled="true"></Switch>
            </NotAuthorized>
        </ResourceAuthorize>
    </FormItem>

    @if (this.Options.Type.Equals(OperationDialogInputType.Edit) || this.Options.Type.Equals(OperationDialogInputType.Select))
    {
        <FormItem Label="@Localizer[nameof(SharedLocalResource.CreatedTime)]">
            <span>@model.CreatedTime.ToString(ClientConstant.DateTimeFormat)</span>
        </FormItem>

    }

    @if (this.Options.Type.Equals(OperationDialogInputType.Edit) || this.Options.Type.Equals(OperationDialogInputType.Select))
    {
        <FormItem Label="@Localizer[nameof(SharedLocalResource.UpdatedTime)]">
            <span>@model.UpdatedTime?.ToString(ClientConstant.DateTimeFormat)</span>
        </FormItem>

    }
    <FormItem WrapperColOffset="8" WrapperColSpan="16">
        <Space>
            @if (!OperationDialogInputType.Select.Equals(this.Options.Type))
            {
                <SpaceItem>
                    <Button Type="@ButtonType.Primary" OnClick="OnGoToSubmit">
                        @Localizer[nameof(SharedLocalResource.Save)]
                    </Button>
                </SpaceItem>
            }
            <SpaceItem>
                <Button OnClick="_=>OnFormCancel()">
                    @Localizer[nameof(SharedLocalResource.Cancel)]
                </Button>
            </SpaceItem>
        </Space>
    </FormItem>
</Form>